<div class="container-fluid">
    年:<input type="text" id="year">
    月:<input type="text" id="month"/>
    <button class="btn btn-primary" type="button" onclick="productReport()">查询</button>
</div>
<table class="table" id="somainDiv">
    <thead>
    <tr>
        <th>产品总数</th>
        <th>产品总库存数</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody id="tableBody">
    <tr>
        <td id="productNum"></td>
        <td id="productInStoreNum"></td>
        <td hidden id="button"><input type="button" value="查看明细" onclick="toProductItemReport()"></td>
    </tr>
    </tbody>
</table>
<script>
    function productReport() {
        var year = $("#year").val()
        var month = $("#month").val()
        if (Number(month) < 9) {
            var date = year + "-0" + month + "~" + year + "-0" + (Number(month) + 1)
        }
        if (Number(month) == 9) {
            var date = year + "-0" + month + "~" + year + "-" + (Number(month) + 1)
        }
        if (Number(month) > 9) {
            var date = year + "-" + month + "~" + year + "-" + (Number(month) + 1)
        }
        window.sessionStorage.setItem("productdate", date)
        Ajax.post(
            "/selectProductReport",
            {date: date},
            function (result) {
                document.getElementById("productNum").innerText = result.data.length
                var sum = 0
                for (var i = 0; i < result.data.length; i++) {
                    sum = sum + result.data[i].num
                }
                document.getElementById("productInStoreNum").innerText = sum
            }
        )
        $("#button").attr("hidden",false)
    }
    function toProductItemReport() {
        show("/report/productItemReport.html")
    }
</script>